﻿using A.M.ETO;
using AutoMapper;
using DotNetCore.CAP;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using Q.M.Finance.Application.IServices;
using Q.M.Finance.Domain.DTO;
using Q.M.Finance.Domain.Entity;
using Q.M.Finance.Infrastruecure.Repository;
using System.Linq.Expressions;

namespace Q.M.Finance.Write.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Billing_managementWriteController : ControllerBase
    {
        private readonly IBilling_managementServices billing_ManagementServices;
        public Billing_managementWriteController(IBilling_managementServices billing_managementServices)
        {
            this.billing_ManagementServices = billing_managementServices;
        }
        /// <summary>
        /// 添加开票管理
        /// </summary>
        /// <param name="billing_ManagementAddDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Getbilling_managementAddInfo(billing_managementAddDTO billing_ManagementAddDTO)
        {
            try
            {
                var res =await billing_ManagementServices.Getbilling_managementAddInfo(billing_ManagementAddDTO);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改开票管理
        /// </summary>
        /// <param name="incomeUpdateDTO"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> Getbilling_managementUpdateInfo(billing_managementShowDTO incomeUpdateDTO)
        {
            var res =await billing_ManagementServices.Getbilling_managementUpdateInfo(incomeUpdateDTO);
            return Ok(res);
        }
        /// <summary>
        /// 反填开票管理
        /// </summary>
        /// <param name="invoiceid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Findbilling_managementInfo(string? invoiceid)
        {
            var res =await billing_ManagementServices.Findbilling_managementInfo(invoiceid);
            return Ok(res);
        }

        /// <summary>
        /// 删除开票管理
        /// </summary>
        /// <param name="invoiceid"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> Deletebilling_management(string? invoiceid)
        {
            var res =await billing_ManagementServices.Deletebilling_management(invoiceid);
            return Ok(res);
        }
        /// <summary>
        /// 收入开票显示+分页+查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Getbilling_managementInfo(string? invoiceid, int pageIndex, int pageSize)
        {
            var res = billing_ManagementServices.Getbilling_managementInfo(invoiceid,pageIndex,pageSize);
            return Ok(res);
        }
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ExportTiExcel()
        {
            var list = billing_ManagementServices.GetShowInfor();
            var steram = new MemoryStream();
            steram.SaveAs(list);
            steram.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(steram, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "开票信息.xlsx"
            };
        }
    }
}
